from django import template
from app_article.models import Comment
from django.db.models import F

register = template.Library()


@register.inclusion_tag('article_inclusion_tags/comment_inclusion.html')
def comment_flat(blog_obj, article_now):
    # 获取所有主评论
    _main_comments = Comment.objects.filter(article=article_now).filter(parent=None)
    comment_data_list = []
    for father_comment in _main_comments:
        # 获取所有主评论及其对应的子评论
        child_comment = Comment.objects.filter(parent=father_comment.id)
        # 将主评论和子评论作为元组传入 (主评论对象,子评论queryset)
        comment_data_list.append((father_comment, child_comment))
    return locals()
